package com.zj.esproxy.wrapper;

import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author arthur_zhou
 * @date 2023/11/7 14:17
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Collapse {

    private String field;

    @JSONField(name = "inner_hits")
    private List<InnerHit> innerHits;

    @Data
    public static class InnerHit {
        private String name;
        private Integer size;
        private List<Sort> sort;
    }

    public Collapse(Collapse collapse) {
        if (Objects.isNull(collapse)) {
            return;
        }
        this.field = collapse.field;
        if (CollectionUtil.isNotEmpty(collapse.innerHits)) {
            this.innerHits = new ArrayList<>(collapse.innerHits);
        }

    }
}
